home *** CD-ROM | disk | FTP | other *** search
- Path: uwm.edu!daffy!uwvax!flisakow
- From: flisakow@.cs.wisc.edu (Shaun Flisakowski)
- Newsgroups: comp.lang.c
- Subject: Re: Tradition or what?
- Date: 9 Mar 1996 00:53:17 GMT
- Organization: U of Wisconsin CS Dept
- Message-ID: <4hqkpt$lk7@spool.cs.wisc.edu>
- References: <4g0elg$mdr@redstone.interpath.net> <4hpd8a$d70@alterdial.UU.NET> <1996Mar8.153250.115645@kuhub.cc.ukans.edu> <4hqhge$2gu@solutions.solon.com>
- NNTP-Posting-Host: trigger.cs.wisc.edu
-
- In article <4hqhge$2gu@solutions.solon.com>,
- Peter Seebach <seebs@solutions.solon.com> wrote:
- >In article <1996Mar8.153250.115645@kuhub.cc.ukans.edu>,
- > <anh@kuhub.cc.ukans.edu> wrote:
- >>Well, I found one good use of magic numbers such as when one needs a
- >>localized temporary buffer of data.
- >
- >>int func()
- >>{
- >> FILE *fp;
- >> char buf[15+1];
- >
- >> ...
- >
- >> fgets(buf,15,fp);
- >>}
- >
- >>Well, if I know the data is always going to be less than 15 or whatever,
- >>there is really no need to use a #define here.
- >
- >Anyway, I'd rather see a 15 in both places, and over that, I'd prefer to
- >see a #define or enum used. If you know the data is always going to be
- [snip]
-
- I agree, for small little things like this, I sympathize with
- the original author though, and drop in the define in-line,
- undefining it at the end of that function:
-
- int func()
- {
-
- FILE *fp;
- #define BUFF_SZE 15
- char buf[BUFF_SZE];
-
- ...
-
- fgets(buf,BUFF_SZE,fp);
-
- ...
-
- #undef BUFF_SZE
- }
-
-
- --
- Shaun flisakow@cs.wisc.edu
-
- "In your heart you know its flat."
- -Flat Earth Society
-